package com.xuyaxu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 连接测试
 *
 * @author xuyaxu
 * @date 2022/7/19 21:22
 */
@RestController
@RequestMapping("/redisTest")
public class RedisTestController {

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping
    public String redisTest() {
        //设置值到 redis
        redisTemplate.opsForValue().set("name", "lucy");
        //从 redis 获取值
        String name = (String) redisTemplate.opsForValue().get("name");
        return name;
    }
}
